package com.guass.nettyprotostuff.disruptor;

import com.guass.nettyprotostuff.service.RpcService;
import com.lmax.disruptor.WorkHandler;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author guass
 * @date 2021年12月22日 17:39
 */
@Data
@Slf4j
public class CommandConsumer implements WorkHandler<TranslatorDataWapper> {

    private String consumerId;

    private RpcService rpcService;

    private int ringBufferSize;

    private int ringSleepTime;

    private int ringDoCount;

    private static AtomicInteger counter = new AtomicInteger(0);

    public CommandConsumer(String consumerId, RpcService rpcService,int ringBufferSize, int ringSleepTime, int ringDoCount) {
        this.consumerId = consumerId;
        this.rpcService = rpcService;
        this.ringBufferSize = ringBufferSize;
        this.ringSleepTime = ringSleepTime;
        this.ringDoCount = ringDoCount > 0 ? ringDoCount: 128;
    }

    @Override
    public void onEvent(TranslatorDataWapper event) {

        log.info("guass disruptor comsumer {}", event.getModelMsg());
        if (rpcService != null) {
            rpcService.onDataReceive(event.getCtx(),event.getModelMsg());
        }

    }




}
